$(function() {
//Declare variable
	var button_name="",
		url="a_stock.php", 
		ID="",
		mode="",
		rowSelect="";
		
		LoadData(1,false);
	
		   
		//Show Loading bar			
		function showLoader(){
			var col=16;
			if($("#isHO").val()==1)
				col=16;
			else 
				col=16;
				
			$( "#resultData tbody:first" ).prepend( "<tr>"
						+"<td colspan="+col+" class='search-background'>"
						+"<label><img src='./images/ajax-loader.gif'/></label>"
						+"</td>"
						+"</tr>" ); 
			 $('.search-background').fadeIn(900,0);
		}
		//Hide Loading bar			
		function hideLoader(){
			$('.search-background').fadeOut(300);
			$( "#resultData tbody tr" ).remove();
		};
 
		//b=false , don't gennerate paging
		function LoadData(page,b){
			$( "#resultData tbody tr" ).remove();
			//Show loading
			showLoader();
 
				
			 //Post 			
			var data={};
			data={'m':'print'
				,'branch':$("#branch").val()
				,'productname':$("#product").val()
				,'category':$("#category").val()			
				,'type':0//$("#cboType").val()	
				,'pos':$("#pos").val()	
				,'stock':$("#stock").val()	
				,'premium':$("#premium").val()	
				,'page':page};
						
			$.post(url,data,function(data){
			 //alert(data);
				var obj=eval("(" + data + ")");
				//hide loading
				hideLoader();			
				//set data to table
				$( "#resultData tbody" ).append(obj['data']);
				//set row 
				$("#rowCount").attr('innerHTML',obj['rows']);
				//set page
				if (b){
					var p="<ul>";
					for (var i=parseInt(obj['totalpage']);i >0 ;i--){
						p = p +'<li id="'+i+'">'+i+'</li>';
					}
					p = p+"</ul>";
					$("#paging_button ul").remove();
					$("#paging_button").append(p);
					 
				}
				$("#"+page).css({'background-color' : '#006699'});
				
				 window.print();
			});
			
		}	
  
});
	